﻿using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class PathTool
{
    public static string FilePathToAssetPath(string path)
    {
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            return path.Substring(path.IndexOf("Assets\\"));
        }
        else
        {
            return path.Substring(path.IndexOf("Assets/"));
        }
    }

    public static string GetRawPath(string path)
    {
        return path.Replace("\\", "/");
    }

    public static string GetRelativeAssetsPath(string path)
    {
        return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
    }

    public static void GetAllFilePath(string path, List<string> files)
    {
        string[] names = Directory.GetFiles(path);
        string[] dirs = Directory.GetDirectories(path);
        foreach (string filename in names)
        {
            string ext = Path.GetExtension(filename);
            if (ext.Equals(".meta"))
                continue;
            files.Add(filename.Replace('\\', '/'));
        }
        foreach (string dir in dirs)
        {
            GetAllFilePath(dir, files);
        }
    }

    public static string PlatformName
    {
        get
        {
#if UNITY_EDITOR
            UnityEditor.BuildTarget target = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
            switch (target)
            {
                case UnityEditor.BuildTarget.StandaloneWindows:
                case UnityEditor.BuildTarget.StandaloneWindows64:
                    return "windows";
                case UnityEditor.BuildTarget.Android:
                    return "android";
                case UnityEditor.BuildTarget.iOS:
                    return "ios";
                case UnityEditor.BuildTarget.StandaloneOSXIntel:
                case UnityEditor.BuildTarget.StandaloneOSXIntel64:
                case UnityEditor.BuildTarget.StandaloneOSXUniversal:
                    return "osx";
                case UnityEditor.BuildTarget.WebGL:
                    return "webgl";
                default:
                    return null;
            }
#else
                RuntimePlatform platform = Application.platform;
                switch (platform)
                {
                    case RuntimePlatform.WindowsPlayer:
                    case RuntimePlatform.WindowsEditor:
                        return "windows";
                    case RuntimePlatform.Android:
                        return "android";
                    case RuntimePlatform.IPhonePlayer:
                        return "ios";
                    case RuntimePlatform.OSXPlayer:
                        return "osx";
                    case RuntimePlatform.WebGLPlayer:
                        return "webgl";
                    default:
                        return null;
                }
#endif
        }
    }
}